package com.ym.b2b.upload.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.commons.dao.BaseDao;
import com.ym.b2b.upload.dao.EmBUploadDAO;
import com.ym.b2b.upload.sqlbean.EmBUpload;
import com.zc.commons.base.Page;

@Repository
public class EmBUploadDAOImpl<T> extends BaseDao<T> implements EmBUploadDAO {

    @Override
    public Long searchPageEmBUploadNum(EmBUpload embupload) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embupload);
        return (Long) listNum("EM_B_UPLOAD.searchPageEmBUploadNum", map);
    }

    @Override
    public Page searchPageEmBUpload(EmBUpload embupload, Page<EmBUpload> page) throws DataAccessException {
    	if("all".equals(embupload.getFileType())){
    		embupload.setFileType(null);
    	}
        page.setTotalRow(searchPageEmBUploadNum(embupload));
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embupload);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());

        page.setRows(list("EM_B_UPLOAD.searchPageEmBUpload", map));
        return page;
    }

    @Override
    public void insertEmBUpload(EmBUpload record) throws DataAccessException {
        insert("EM_B_UPLOAD.insertEmBUpload", record);
    }

    @Override
    public int updateEmBUpload(EmBUpload record) throws DataAccessException {
        int rows = sqlMapClient.update("EM_B_UPLOAD.updateEmBUpload", record);
        return rows;
    }

    @Override
    public EmBUpload searchEmBUpload(Long uploadId) throws DataAccessException {
        EmBUpload key = new EmBUpload();
        key.setUploadId(uploadId);
        EmBUpload record = (EmBUpload) find("EM_B_UPLOAD.searchEmBUpload", key);
        return record;
    }

    @Override
    public int deleteEmBUpload(Long uploadId) throws DataAccessException {
        EmBUpload key = new EmBUpload();
        key.setUploadId(uploadId);
        int rows = sqlMapClient.delete("EM_B_UPLOAD.deleteEmBUpload", key);
        return rows;
    }

    @Override
    public int deleteMultipleEmBUpload(String uploadIdList) {
        int rows = delete("EM_B_UPLOAD.deleteMultipleEmBUpload", uploadIdList);
        return rows;
    }
}
